package cn.yudao.ymcc.mq.producer;

import cn.yudao.ymcc.dto.OnLineSmsDto;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class OnLineSmsProducer {


    @Autowired
    private  RocketMQTemplate rocketMQTemplate;

    public  boolean sendProductMessage(OnLineSmsDto onLineSmsDto){
        Message<OnLineSmsDto> build = MessageBuilder.withPayload(onLineSmsDto).build();
        System.out.println(rocketMQTemplate);
        SendResult sendResult = rocketMQTemplate.syncSend("topic-online:rag-sms", build);
        if (sendResult.getSendStatus() == SendStatus.SEND_OK){
            return true;
        }
        return false;
    }


}
